package com.example.iotmanagerment26.service.impl;


import com.example.iotmanagerment26.domain.Room;
import com.example.iotmanagerment26.mapper.RoomMapper;
import com.example.iotmanagerment26.service.RoomService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service
public class RoomSeviceImpl implements RoomService {
    @Resource
    RoomMapper roomMapper;

    @Override
    public List<Room> selectAllRoom() {
        return roomMapper.selectAllRoom();
    }

    @Override
    public List<Room> selectRoomInfoByName(String roomName) {
        return roomMapper.selectRoomInfoByName(roomName);
    }

    @Override
    public int insertRoom(String name) {
        int n = roomMapper.isEmptyRoom(name);
        if (n>=1){
            return -1;
        }else {
            return roomMapper.insertRoom(name);
        }
    }

    @Override
    public int deleteRoom(String name) {
        int n = roomMapper.deleteRoom(name);
        roomMapper.deleteRoomDevice2(name);
        roomMapper.deleteRoomUser2(name);
        return n;
    }

    @Override
    public int insertRoomUser(String name, String user) {
        if (roomMapper.isEmptyRoom(name)>=1) {
            int n = roomMapper.isEmptyRoomUser(name,user);
            if (n>=1){
                return -1;
            }else {
                return roomMapper.insertRoomUser(name,user);
            }
        }else {
            return -2;
        }
    }

    @Override
    public int insertRoomDevice(String name, String device) {
        if (roomMapper.isEmptyRoom(name)>=1) {
            int n = roomMapper.isEmptyRoomDevice(name,device);
            if (n>=1){
                return -1;
            }else {
                return roomMapper.insertRoomDevice(name,device);
            }
        }else {
            return -2;
        }
    }

    @Override
    public int deleteRoomDevice(String name, String device) {
        return roomMapper.deleteRoomDevice(name,device);
    }

    @Override
    public int deleteRoomUser(String name, String user) {
        return roomMapper.deleteRoomUser(name,user);
    }

    @Override
    public List<Map<String, Object>> selectAllUnbindRoomUser() {
        return roomMapper.selectAllUnbindRoomUser();
    }

    @Override
    public List<Map<String, Object>> selectAllUnbindRoomDevice() {
        return roomMapper.selectAllUnbindRoomDevice();
    }

    @Override
    public List<Map<String,Object>> selectRoomAndDeviceByUser(String userName) {
        return roomMapper.selectRoomAndDeviceByUser(userName);
    }


}
